package com.service.ua;

import com.bpms.common.Base64;
import com.bpms.common.CommonUtil;
import com.bpms.common.Db;
import com.bpms.common.EnDES;
import com.bpms.common.VO;
import com.bpms.esb.IService;

public class Changepwd implements IService {
	
	/**
	 * 输入参数
	 * userid	用户id
	 * pwd	原始密码
	 * newpwd	新密码
	 * confirmnewpwd 确认新密码
	 * 输出参数
	 * user信息
	 * result 0000成功 1111失败 9999其他
	 * msg 描述
	 */
	public VO exec(VO args) {
		VO vo = new VO();
		if (args == null)
			return null;
		String userid = args.getAttr("userid");
		String pwd = args.getAttr("pwd");
		String newpwd = args.getAttr("newpwd");
		String confirmnewpwd = args.getAttr("confirmnewpwd");
		
//		String enpwd=new EnDES().encrypt(pwd);
//		String desPwd = Base64.encodeBytes(enpwd.getBytes());
		//CommonUtil.debug(desPwd);
		try {
			Db j = new Db();
			VO uservo = j.readInCombination(
					new VO(),
					"select * from BPM_USER where userid='"
							+ userid + "'");
			if (uservo == null)
				return null;
			if (!pwd.equals(uservo.getAttr("passwd"))) {
				vo.setAttr("result", "9999");
				vo.setAttr("msg",
						"7006");
				return vo;
			} else if (!newpwd.equals(confirmnewpwd)) {
				vo.setAttr("result", "9999");
				vo.setAttr("msg", "7007");
				return vo;
			}
//			String enNewpwd=new EnDES().encrypt(newpwd);
//			String desNewPwd = Base64.encodeBytes(enNewpwd.getBytes());
			
			
			VO keyVO = new VO();
			VO updateVO = new VO();
			keyVO.voType = "bpm_user";
			keyVO.isAutoKey = false;
			keyVO.keyString = "userid";
			keyVO.setAttr("userid", args.getAttr("USERID"));
			updateVO.setAttr("passwd", newpwd);
			j.update(updateVO, keyVO);
			uservo.setAttr("result", "0000");
			uservo.setAttr("passwd", newpwd);
			return uservo;
		} catch (Exception e) {
			vo.setAttr("result", "9999");
			vo.setAttr("msg", "7008");
			CommonUtil.debug("ua.Changepwd exception", e);
			return vo;
		}

	}

}
